package com.thinkingcoder.tccache.core.command.zset;

import static com.thinkingcoder.tccache.constant.CommandConstants.ZSetCmd.ZCOUNT;

import com.thinkingcoder.tccache.core.TcCache;
import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.model.Reply;

/**
 * ZCOUNT command.
 */
public class ZCountCmd implements Command {
    @Override
    public String name() {
        return ZCOUNT;
    }

    @Override
    public Reply<?> exec(TcCache cache, String[] args) {
        String key = getKey(args);
        String[] vals = getParamsNoKey(args);
        double min = Double.parseDouble(vals[0]);
        double max = Double.parseDouble(vals[1]);
        return Reply.integer(cache.zCount(key, min, max));
    }
}
